<?php

class UserController extends Controller {
	
    public function __construct($data) {
        parent::__construct($data);

    }
	public function index() {
		require_once( '../system/ecjp_m.php' );
		$this->assign('states', $ecjp_user_state);
		$this->assign('sends', $ecjp_user_send);
		
		//$this->_load_php_file( 'ecjp_m.php' );
		
		//ヘッド、メニューなどsmarty設定
		$this->_set_head_footer();
		
		$this->_load_Class_DAO_OTHER();
		$dao_local = Class_DAO_OTHER::get_local_array('都道府県');
		if (isset($dao_local)){
		 	$this->assign('dao_local', $dao_local);
		}
		require( '../system/mdao/t_m_user.php' );
		
		
		
		 $sql = 'SELECT * FROM  m_user';
		 
		 
		 
		 $user_dao = new t_m_user;
		 $user_data=$user_dao->get_rows($sql);
		  if (isset($user_dao)){
           $this->assign('data',$user_data);
		  }
		
		  $is_showlist=true;
		 
		 $this->assign('is_showlist',$is_showlist);
		
		$this->display('user_index.html');
	}
	
	


	
	public function p_get_where($forms,$dao) {
       
	}
	
    public function search() {
    	//ヘッド、メニューなどsmarty設定
		$this->_set_head_footer();
		
    	require_once( '../system/ecjp_m.php' );
		$this->assign('states', $ecjp_user_state);
		$this->assign('sends', $ecjp_user_send);
		
		//require( '../system/mdao/t_m_user.php' );
		$this->_load_mdao_class("t_m_user");
		
		//require( '../system/Class_DAO_OTHER.php' );
		$this->_load_Class_DAO_OTHER();

       
		if ( isset( $forms['csv'] ) &&  (  $forms['csv'] == "download" ) ||
			 isset( $forms['hist'] ) &&  (  $forms['hist'] == "2" ) ) {
			$forms =  $_SESSION['MSEARCH']['USER'];
		}else {
			 $forms = $this->g;
			$_SESSION['MSEARCH']['USER'] = $forms;
		}
 //print_r($forms);
        $dao = new t_m_user;
        $wherearr = array();
        if (isset($forms['free_word']) && (!empty($forms['free_word']) )) {
        	$keyword = '%' .$dao->esc($forms['free_word']). '%';
            $wherearr[] = sprintf("(a.workshop_name like  '%s' or 
	                       a.user_name1 like '%s' or 
	                       a.user_name2 like '%s' or
	                       a.tel_number like '%s' or
	                       a.email like '%s' )", $keyword,  $keyword , $keyword, $keyword,$keyword);
        }
        
        if (isset($forms['local_cd']) && (!empty($forms['local_cd']) )) {
            $wherearr[] = sprintf(" a.local_cd =  '%s' ", $dao->esc($forms['local_cd']));
        }
        
        if (isset($forms['data1']) && (!empty($forms['data1']) )) {
        	$data1=$forms['data1'];
        	$wherearr[] = sprintf("( a.u_time > '%s')",$data1);
        }
        if (isset($forms['data2']) && (!empty($forms['data2']) )) {
        	$data2=$forms['data2'];
        	$wherearr[] = sprintf("( a.u_time< '%s')",$data2);
        }
        
        
        
       // print_r($forms);
        //状態
        $states = null;
        foreach ($ecjp_user_state as $k => $v ) {
        	if (isset($forms["state$k"]) && (!empty($forms["state$k"]) )) {
        		$states[] = " a.state = $k ";
        	}
        }
        if ($states) {
        	$wherearr[] = "(".  implode($states, ' or ' ) . ")";
        }
     //print_r($wherearr);
     	//メルマガ
        $sends = null;
        foreach ($ecjp_user_send as $k => $v ) {
        	if (isset($forms["send$k"]) && (!empty($forms["send$k"]) )) {
        		$sends[] = " a.send = $k ";
        	}
        }
        if ($sends) {
        	$wherearr[] = "(".  implode($sends, ' or ' ) . ")";
        }
        
     
 
        if (isset($forms['csv']) && ( $forms['csv'] == "download" )) {
            $g["csv"] = "";
            $tmpfilename = "user" . date("Ymd_His");
            header("Content-Type: application/octet-stream");
            header("Content-Disposition: attachment; filename=$tmpfilename.csv");
            $colums = array();
            $col_heads = array(
                'login_id' => array('ログインID', 1),
                'login_pwd' => array('パスワード', 1),
                'user_name' => array('ユーザー名', 1),
                'workshop_name' => array('貴医院名・貴技工所名', 1),
                'zipcode' => array('郵便番号', 1),
                'treet_name' => array('市区町村', 1),
                'email' => array('メールアドレス', 1),
                'tel_number' => array('電話番号', 1),
                'status ' => array('状態', 1),
            );
            foreach ($col_heads as $k => $v) {
                $colums["name"][] = $k;
                $colums["head"][] = $v[0];
                $colums["type"][$k] = $v[1];
            }
            $data = $dao->search_csv($wherearr);
            //データ整形開始
            foreach ($data as $k => $v) {
                $data[$k]["user_name"] = $v['user_name1'] . ' ' . $v['user_name2'];
            }
            //データ整形完了
            $dao->output_csv($data, $colums);
            exit;
        }

        if (isset($forms['page']) && is_numeric($forms['page'])) {
            $dosearch = TRUE;
            $page['current'] = $forms['page'];
        } else {
            $page['current'] = 1;
        }
        $page['item'] = PAGE_MAX;
        
  		$dao_local = Class_DAO_OTHER::get_local_array('都道府県');
  		
        $data = $dao->search($wherearr, $page);
      
        if (isset($forms))
            $this->assign('forms', $forms);
        if (isset($data))
            $this->assign('data', $data);
        if (isset($page))
            $this->assign('page', $page);
            
		if (isset($dao_local)){
		 	$this->assign('dao_local', $dao_local);
		}
		
		foreach($forms as $key=>$val){
			
			if($val){
				if($key=='state1' || $key=='state2' || $key=='state3' || $key=='send1' || $key=='send2'  ){
				$forms[$key]="checked";
				}
			}
			
			
			}
			//print_r($forms);
		$this->assign('forms',$forms);
        $this->assign('pageing', $this->fetch('page.html'));
        $this->display('user_index.html');
    }

    public function refer() {
      	//ヘッド、メニューなどsmarty設定
		$this->_set_head_footer();
        $g =  $this->g;
        require_once( '../system/ecjp_m.php' );	
		$this->_load_mdao_class("t_m_user");
		$this->_load_Class_DAO_OTHER();
		
        $dao = new t_m_user;
        if ($_SERVER['REQUEST_METHOD'] == 'GET') {
            if (isset($g['id']) && $g['id'] != '') {
                if (is_numeric($g['id'])) {
                    $forms = $dao->get($g['id']);
                }
            }
            if (isset($forms)) {
                if (isset($forms['birthday'])) {
                    $forms['birthday_year'] = gmdate('Y', strtotime($forms['birthday']));
                    $forms['birthday_m'] = gmdate('m', strtotime($forms['birthday']));
                }
                if (isset($forms['zipcode'])) {
                    $forms['zipcode1'] = substr($forms['zipcode'], 0, 3);
                    $forms['zipcode2'] = substr($forms['zipcode'], 3, strlen($forms['zipcode']) - 1);
                }
            	if (isset($forms['tel_number'])) {
                	$strs = explode('-',$forms['tel_number']);
                    $forms['tel_number1'] = $strs[0];
                    $forms['tel_number2'] = $strs[1];
                    $forms['tel_number3'] = $strs[2];
                }
                if (isset($forms['mobile_number'])) {
                	$strs = explode('-',$forms['mobile_number']);
                    $forms['mobile_number1'] = $strs[0];
                    $forms['mobile_number2'] = $strs[1];
                    $forms['mobile_number3'] = $strs[2];
                }
            }
        }
       
        
        $this->assign('forms', $forms);
       	$this->display('user_refer.html');
	 }
    
    protected  function p_form_index(){
		//ヘッド、メニューなどsmarty設定
		$this->_set_head_footer();
		
		//require( '../system/mdao/t_m_user.php' );
		$this->_load_mdao_class("t_m_user");
		
		//require( '../system/Class_DAO_OTHER.php' );
		$this->_load_Class_DAO_OTHER();
		
		$dao_local = Class_DAO_OTHER::get_local_array('都道府県');
		
		if (isset($dao_local)){
		 	$this->assign('dao_local', $dao_local);
		}
		
       	require_once( '../system/ecjp_m.php' );
		$this->assign('states', $ecjp_user_state);
		$this->assign('sends', $ecjp_user_send);
    }
    
 public function insert(){
    	//ヘッド、メニューなどsmarty設定
    	$this->_set_head_footer();
    	require_once( '../system/ecjp_m.php' );	
    	$g =  $this->g;
    	$this->_load_mdao_class("t_m_user");
    	$this->_load_Class_DAO_OTHER();
  
    	$this->_load_php_file("Class_ERROR.php");
   
    	$this->_load_php_file("Class_FUNC.php");
    
    	$dao = new t_m_user;
    	$show_massg=true;
    
    
    
    
    
    	if ($_SERVER['REQUEST_METHOD'] == 'POST' ) {
    		$forms = $this->p;
    		//$forms['user_name']= $err_mes['user_name1']. $err_mes['user_name2'];
    		//print_r($forms);
    		$err     = new Class_ERROR;
    		$chk     = $dao->get_checks();
    		
    		if($forms['send']==1){
    			$forms['send']=1;
    		}else{
    			$forms['send']=2;
    		}
    		
    	
    		if( $err_mes['login_id'] == '' ){
    			if( $forms['id'] == '' ){
    				$where = sprintf(" login_id = '%s'", $forms['login_id'] );
    			}else{
    				$where = sprintf(" login_id = '%s' AND login_id <> %s", $forms['login_id'], $forms['id'] );
    			}
    			
    			if ( $dao->exits($where) ) {
    				
    				$err->clear = false;
    				$err_mes['login_id'] = '<p class="error">ログインIDでは重複しています</p>';
    			}
    		}
    
    		//$user = $dao->get($g['id']);
    
    		//$forms['c_datetime'] = $user['c_datetime'];
    		//$forms['u_datetime'] = $user['u_datetime'];
    
    		//$forms['local_name'] = $this->p['local_cd'];
    		//$forms['birthday_year'] = $this->p['year4'];
    
    		/* echo "<script>alert('".$forms['user_name2']."')</script>" ;*/
    		//print_r($forms);
    		if(isset($forms['send'])){
    			$forms['send']=1;
    		}else{
    			$forms['send']=2;
    		}
    		
    		$forms['birthday_m']   = $this->p['moon4'];
    		$err_mes['login_id']   = $err->exist_check($forms['login_id']);
    		$err_mes['login_pwd']  = $err->exist_check($forms['login_pwd']);
    		$err_mes['user_name1'] = $err->exist_check($forms['user_name1']);
    		if(!$err_mes['user_name1'])
    		$err_mes['user_name1'] = $err->exist_check($forms['user_name2']);
    		$err_mes['user_name_furikana1'] = $err->exist_check($forms['user_name_furikana1']);
    		if(!$err_mes['user_name_furikana1'])
    		$err_mes['user_name_furikana1'] = $err->exist_check($forms['user_name_furikana2']);
    		$err_mes['zipcode1'] = $err->exist_check($forms['zipcode1']);
    		$err_mes['zipcode1'] = $err->exist_check($forms['zipcode2']);
    		$err_mes['local_cd'] = $err->exist_check($forms['local_cd']);
    		$err_mes['treet_name'] = $err->exist_check($forms['treet_name']);
    		$err_mes['address'] = $err->exist_check($forms['address']);
    		$err_mes['tel_number1'] = $err->exist_check($forms['tel_number1']);
    		if(!$err_mes['tel_number1'])
    		$err_mes['tel_number1'] = $err->exist_check($forms['tel_number2']);
    		if(!$err_mes['tel_number1'])
    		$err_mes['tel_number1'] = $err->exist_check($forms['tel_number3']);
    		$err_mes['email'] = $err->exist_check($forms['email']);
    		$err_mes['state'] = $err->exist_check($forms['state']);
    		
    		
    		
    		
    		
    
    		if ($err->clear) {
    			$err_mes['email'] = $err->mail_check($forms['email']);
    			$err_mes['zipcode'] = $err->zipcode_check($forms['zipcode1'] . '-' . $forms['zipcode2']);
    			$err_mes['tel_number'] = $err->tel_check($forms['tel_number1'] . '-' . $forms['tel_number2'] . '-' . $forms['tel_number3']);
    			$err_mes['login_id'] = $err->alnum_check($forms['login_id']);
    			$err_mes['login_pwd'] = $err->alnum_check($forms['login_pwd']);
    			$err_mes['workshop_name_furikana'] = $err->katakana_check($forms['workshop_name_furikana']);
    			$err_mes['user_name_furikana1'] = $err->katakana_check($forms['user_name_furikana1']);
    			
    			if(!$err_mes['user_name_furikana1'])
    				$err_mes['user_name_furikana1'] = $err->katakana_check($forms['user_name_furikana2']);
    		
    		}
    		
    		if ($err->clear) {
    			$values["login_id"] = $forms['login_id'];
    			$values["login_pwd"] = $forms['login_pwd'];
    			$values["user_name1"] = $forms['user_name1'];
    			$values["user_name2"] = $forms['user_name2'];
    			$values["user_name_furikana1"] = $forms['user_name_furikana1'];
    			$values["user_name_furikana2"] = $forms['user_name_furikana2'];
    			$values["workshop_name"] = $forms['workshop_name'];
    			$values["workshop_name_furikana"] = $forms['workshop_name_furikana'];
    			$values["zipcode"] = $forms['zipcode1'] ."-". $forms['zipcode2'];
    			$values["local_cd"] = $forms['local_cd'];
    			$values["treet_name"] = $forms['treet_name'];
    			$values["address"] = $forms['address'];
    			$values["tel_number"] = $forms['tel_number1'] ."-". $forms['tel_number2'] ."-". $forms['tel_number3'];
    			$values["mobile_number"] = $forms['mobile_number1'] ."-". $forms['mobile_number2'] ."-". $forms['mobile_number3'];
    			$values["email"] = $forms['email'];
    			$values["send"] = $forms['send'];
    			$values["sex"] = $forms['sex'];
    			$values["state"] = $forms['state'];
    			$values["birth"] = $forms['year4'] . '-' . $forms['moon4'] . '-01';
    			$values["retreat"] = $forms['retreat_account'];
    			
    			
    			
    			if($dao->add0($values)){
    				$this->assign('message', '登録が完了しました。');
    				
    			}else{
    				$this->assign('message', '登録が失敗しました。');
    				
    			}
    			$show_massg=false;
    
    		}
    	}
    	$dao_local = Class_DAO_OTHER::get_local_array('都道府県');
    	
    	$this->assign('year4', Class_FUNC::get_years());
    	$this->assign('moon4', Class_FUNC::get_moons());
    
    	if (isset($dao_local))
    		$this->assign('dao_local', $dao_local);
    	if (isset($forms))
    		$this->assign('forms', $forms);
    	if (isset($err_mes)) {
    		$this->assign('err', $err_mes);
    	}
    
    	$this->assign('show_massg',$show_massg);
    	$this->display('user_regist.html');
    }
    public function update() {
    	//ヘッド、メニューなどsmarty設定
 
		$this->_set_head_footer();
		require_once( '../system/ecjp_m.php' );	
        $g =  $this->g;
		$this->_load_mdao_class("t_m_user");
		$this->_load_Class_DAO_OTHER();
      //  require_once( '../system/Class_ERROR.php' );
         $this->_load_php_file("Class_ERROR.php");
      // require_once( '../system/Class_FUNC.php' );
      	$this->_load_php_file("Class_FUNC.php");
      	$show_massg=true;
        
        $dao = new t_m_user;

        
        if ($_SERVER['REQUEST_METHOD'] == 'GET') {
            if (isset($g['id']) && $g['id'] != '') {
                if (is_numeric($g['id'])) {
                    $forms = $dao->get($g['id']);
                }
            }
            
            if (isset($forms)) {
                if (isset($forms['birthday'])) {
                   $forms['birthday_year'] = gmdate('Y', strtotime($forms['birthday']));
               // echo    $forms['birthday_year']=substr($forms['birthday'],0,4);
				//echo '------';
            // echo   $forms['birthday_m']=substr($forms['birthday'],4,2);
                	$forms['birthday_m'] = gmdate('m', strtotime($forms['birthday']));
                }
                if (isset($forms['zipcode'])) {
                	$strs = explode('-',$forms['zipcode']);
                    $forms['zipcode1'] = $strs[0];
                    $forms['zipcode2'] = $strs[1];
                }
                if (isset($forms['tel_number'])) {
                	$strs = explode('-',$forms['tel_number']);
                    $forms['tel_number1'] = $strs[0];
                    $forms['tel_number2'] = $strs[1];
                    $forms['tel_number3'] = $strs[2];
                }
                if (isset($forms['mobile_number'])) {
                	$strs = explode('-',$forms['mobile_number']);
                    $forms['mobile_number1'] = $strs[0];
                    $forms['mobile_number2'] = $strs[1];
                    $forms['mobile_number3'] = $strs[2];
                }
            }
        }

  
        if ($_SERVER['REQUEST_METHOD'] == 'POST' ) {
        	 $forms = $this->p;
       
        	if($forms['send1']){$forms['send']=1;}elseif($forms['send2']){$forms['send']=2;}
		     $err     = new Class_ERROR;
			 $chk     = $dao->get_checks();
			
			$forms['user_name']= $err_mes['user_name1']. $err_mes['user_name2'];
			
			
        	
	        if( $err_mes['login_id'] == '' ){
				if( $forms['id'] == '' ){
					$where = sprintf(" login_id = '%s'", $forms['login_id'] );
				}else{
					$where = sprintf(" login_id = '%s' AND login_id <> %s", $forms['login_id'], $forms['id'] );
				}
				
		
			}
			
            $forms['birthday_m']   = $this->p['moon4'];
            $err_mes['login_id']   = $err->exist_check($forms['login_id']);
            $err_mes['login_pwd']  = $err->exist_check($forms['login_pwd']);
            $err_mes['user_name1'] = $err->exist_check($forms['user_name1']);
            $err_mes['user_name1'] = $err->exist_check($forms['user_name2']);
            $err_mes['user_name_furikana1'] = $err->exist_check($forms['user_name_furikana1']);
            if( $err_mes['user_name_furikana1'])
          	  $err_mes['user_name_furikana1'] = $err->exist_check($forms['user_name_furikana2']);

            $err_mes['zipcode1'] = $err->exist_check($forms['zipcode1']);
            if(!$err_mes['zipcode1'])
            	$err_mes['zipcode1'] = $err->exist_check($forms['zipcode2']);
            $err_mes['local_cd'] = $err->exist_check($forms['local_cd']);
           	$err_mes['treet_name'] = $err->exist_check($forms['treet_name']);
            $err_mes['address'] = $err->exist_check($forms['address']);
            $err_mes['tel_number1'] = $err->exist_check($forms['tel_number1']);
            if(!$err_mes['tel_number1'])
           		 $err_mes['tel_number1'] = $err->exist_check($forms['tel_number2']);
            if(!$err_mes['tel_number1'])
          	  $err_mes['tel_number1'] = $err->exist_check($forms['tel_number3']);
            $err_mes['email'] = $err->exist_check($forms['email']);
            $err_mes['state'] = $err->exist_check($forms['state']);
         
            if(isset($forms['send'])){
            	$forms['send']=1;
            }else{
            	$forms['send']=2;
            }
         
            if ($err->clear) {
                $err_mes['email'] = $err->mail_check($forms['email']);
                $err_mes['zipcode'] = $err->zipcode_check($forms['zipcode1'] . '-' . $forms['zipcode2']);
                $err_mes['tel_number'] = $err->tel_check($forms['tel_number1'] . '-' . $forms['tel_number2'] . '-' . $forms['tel_number3']);
                $err_mes['login_id'] = $err->alnum_check($forms['login_id']);
                $err_mes['login_pwd'] = $err->alnum_check($forms['login_pwd']);
                $err_mes['workshop_name_furikana'] = $err->katakana_check($forms['workshop_name_furikana']);
                $err_mes['user_name_furikana1'] = $err->katakana_check($forms['user_name_furikana1']);
			if(!$err_mes['user_name_furikana1'])
                $err_mes['user_name_furikana1'] = $err->katakana_check($forms['user_name_furikana2']);
                
            }
            
          
            if ($err->clear) {
            	$values["login_id"] = $forms['login_id'];
            	$values["login_pwd"] = $forms['login_pwd'];
            	$values["user_name1"] = $forms['user_name1'];
            	$values["user_name2"] = $forms['user_name2'];
            	$values["user_name_furikana1"] = $forms['user_name_furikana1'];
            	$values["user_name_furikana2"] = $forms['user_name_furikana2'];
            	$values["workshop_name"] = $forms['workshop_name'];
            	$values["workshop_name_furikana"] = $forms['workshop_name_furikana'];
            	$values["zipcode"] = $forms['zipcode1'] ."-". $forms['zipcode2'];
            	$values["local_cd"] = $forms['local_cd'];
            	$values["treet_name"] = $forms['treet_name'];
            	$values["address"] = $forms['address'];
            	//$values["tel_number"] = $forms['tel_number1'] . $forms['tel_number2'] . $forms['tel_number3'];
            	$values["tel_number"] = $forms['tel_number1']."-".$forms['tel_number2']."-".$forms['tel_number3'];
            	
            	$values["mobile_number"] = $forms['mobile_number1'] ."-". $forms['mobile_number2'] ."-". $forms['mobile_number3'];
            	$values["email"] = $forms['email'];
            	$values["send"] = $forms['send'];
            	$values["sex"] = $forms['sex'];
            	$values["state"] = $forms['state'];
            	$values["birth"] = (int)($forms['year4'].$forms['moon4']);
            	$values["retreat"] = $forms['retreat'];
            	
          
                $dao->edit($forms['id'], $values);
				
            }
        }
		
		if( $err->clear ){
			
			if( $forms['id'] == '' ){
				if ($dao->add0($values)) {
					$forms['id'] = $id;
					$this->assign('message', '登録が完了しました。');
					
				} else {
					
					$this->assign('message', '登録が失敗しました。');
				}
			}else{
				if ($dao->edit( $forms['id'], $values )) {
					//ECHO '更新が完了しました。';
					$this->assign('message', '更新が完了しました。');
				} else {
					$this->assign('message', '更新が失敗しました。');
				}
				$id = $forms['id'];
			}
			$phase = 'complete';
			$show_massg=false;
		}else{
			$phase = 'input';
		}
		
        $dao_local = Class_DAO_OTHER::get_local_array('都道府県');
        
        $this->assign('year4', Class_FUNC::get_years());
        $this->assign('moon4', Class_FUNC::get_moons());
        
        

        
        if(!isset($forms['year4'])){
        	//$arr=explode('-',$forms['birth']);
        $forms['birthday_year']=substr($forms['birth'],0,4);
        	
        $forms['birthday_m']=substr($forms['birth'],4,2);
        	
        	//$forms['birthday_year']=$arr[0];
        	//$forms['birthday_m']=$arr[1];
        	}
        
        
 
		if( isset( $err_mes ) )  
			$this->assign('err_mes', $err_mes);
		
        if (isset($dao_local))
            $this->assign('dao_local', $dao_local);
        
        if (isset($forms))
        	 $this->assign('forms', $forms);
        if (isset($err_mes)) {
            $this->assign('err', $err_mes);
        }
        

        $this->assign('show_massg',$show_massg);
        
        $this->display('user_form.html');
    }
	
    public function regist(){
    	//ヘッド、メニューなどsmarty設定
    	$this->_set_head_footer();
    	require_once( '../system/ecjp_m.php' );	 
    	$g =  $this->g;
    	$this->_load_mdao_class("t_m_user");
    	$this->_load_Class_DAO_OTHER();
  
    	$this->_load_php_file("Class_ERROR.php");
   
    	$this->_load_php_file("Class_FUNC.php");
    
    	$dao = new t_m_user;
    	$show_massg=true;
    
    
    
    
    
    	if ($_SERVER['REQUEST_METHOD'] == 'POST' ) {
    		$forms = $this->p;
    		//$forms['user_name']= $err_mes['user_name1']. $err_mes['user_name2'];
    		//print_r($forms);
    		$err     = new Class_ERROR;
    		$chk     = $dao->get_checks();
    		
    		if($forms['send']==1){
    			$forms['send']=1;
    		}else{
    			$forms['send']=2;
    		}
    		
    	
    		if( $err_mes['login_id'] == '' ){
    			if( $forms['id'] == '' ){
    				$where = sprintf(" login_id = '%s'", $forms['login_id'] );
    			}else{
    				$where = sprintf(" login_id = '%s' AND login_id <> %s", $forms['login_id'], $forms['id'] );
    			}
    			
    			if ( $dao->exits($where) ) {
    				
    				$err->clear = false;
    				$err_mes['login_id2'] = '<p class="error">ログインIDでは重複しています</p>';
    			}
    		}
    
    		//$user = $dao->get($g['id']);
    
    		//$forms['c_datetime'] = $user['c_datetime'];
    		//$forms['u_datetime'] = $user['u_datetime'];
    
    		//$forms['local_name'] = $this->p['local_cd'];
    		//$forms['birthday_year'] = $this->p['year4'];
    
    		/* echo "<script>alert('".$forms['user_name2']."')</script>" ;*/
    		//print_r($forms);
    		if(isset($forms['send'])){
    			$forms['send']=1;
    		}else{
    			$forms['send']=2;
    		}
    		
    		$forms['birthday_m']   = $this->p['moon4'];
    		$err_mes['login_id']   = $err->exist_check($forms['login_id']);
    		$err_mes['login_pwd']  = $err->exist_check($forms['login_pwd']);
    		$err_mes['user_name1'] = $err->exist_check($forms['user_name1']);
    		if(!$err_mes['user_name1'])
    		$err_mes['user_name1'] = $err->exist_check($forms['user_name2']);
    		$err_mes['user_name_furikana1'] = $err->exist_check($forms['user_name_furikana1']);
    		if(!$err_mes['user_name_furikana1'])
    		$err_mes['user_name_furikana1'] = $err->exist_check($forms['user_name_furikana2']);
    		
    		$err_mes['zipcode1'] = $err->exist_check($forms['zipcode1']);
    		
    		if(!$err_mes['zipcode1'])
    		$err_mes['zipcode1'] = $err->exist_check($forms['zipcode2']);
    		$err_mes['local_cd'] = $err->exist_check($forms['local_cd']);
    		$err_mes['treet_name'] = $err->exist_check($forms['treet_name']);
    		$err_mes['address'] = $err->exist_check($forms['address']);
    		$err_mes['tel_number1'] = $err->exist_check($forms['tel_number1']);
    		if(!$err_mes['tel_number1'])
    			$err_mes['tel_number1'] = $err->exist_check($forms['tel_number2']);
    		if(!$err_mes['tel_number1'])
    			$err_mes['tel_number1'] = $err->exist_check($forms['tel_number3']);
    		$err_mes['email'] = $err->exist_check($forms['email']);
    		$err_mes['state'] = $err->exist_check($forms['state']);
    		
    		
    		
    		
    		
    
    		if ($err->clear) {
    			$err_mes['email'] = $err->mail_check($forms['email']);
    			$err_mes['zipcode'] = $err->zipcode_check($forms['zipcode1'] . '-' . $forms['zipcode2']);
    			$err_mes['tel_number'] = $err->tel_check($forms['tel_number1'] . '-' . $forms['tel_number2'] . '-' . $forms['tel_number3']);
    			$err_mes['login_id'] = $err->alnum_check($forms['login_id']);
    			$err_mes['login_pwd'] = $err->alnum_check($forms['login_pwd']);
    			$err_mes['workshop_name_furikana'] = $err->katakana_check($forms['workshop_name_furikana']);
    			$err_mes['user_name_furikana1'] = $err->katakana_check($forms['user_name_furikana1']);
    			if(!$err_mes['user_name_furikana1'])
    			$err_mes['user_name_furikana1'] = $err->katakana_check($forms['user_name_furikana2']);
    		
    		}
    		
    		if ($err->clear) {
    			$values["login_id"] = $forms['login_id'];
    			$values["login_pwd"] = $forms['login_pwd'];
    			$values["user_name1"] = $forms['user_name1'];
    			$values["user_name2"] = $forms['user_name2'];
    			$values["user_name_furikana1"] = $forms['user_name_furikana1'];
    			$values["user_name_furikana2"] = $forms['user_name_furikana2'];
    			$values["workshop_name"] = $forms['workshop_name'];
    			$values["workshop_name_furikana"] = $forms['workshop_name_furikana'];
    			$values["zipcode"] = $forms['zipcode1'] ."-". $forms['zipcode2'];
    			$values["local_cd"] = $forms['local_cd'];
    			$values["treet_name"] = $forms['treet_name'];
    			$values["address"] = $forms['address'];
    			$values["tel_number"] = $forms['tel_number1'] ."-". $forms['tel_number2'] ."-". $forms['tel_number3'];
    			$values["mobile_number"] = $forms['mobile_number1'] ."-". $forms['mobile_number2'] ."-". $forms['mobile_number3'];
    			$values["email"] = $forms['email'];
    			$values["send"] = $forms['send'];
    			$values["sex"] = $forms['sex'];
    			$values["state"] = $forms['state'];
    			$values["birth"] = (int)($forms['year4'].$forms['moon4']);
    			$values["retreat"] = $forms['retreat_account'];
    			
    			
    			
    			if($dao->add0($values)){
    				$this->assign('message', '登録が完了しました。');
    				
    			}else{
    				$this->assign('message', '登録が失敗しました。');
    				
    			}
    			$show_massg=false;
    
    		}
    	}
    	$dao_local = Class_DAO_OTHER::get_local_array('都道府県');
    	
    	$this->assign('year4', Class_FUNC::get_years());
    	$this->assign('moon4', Class_FUNC::get_moons());
    
    	if (isset($dao_local))
    		$this->assign('dao_local', $dao_local);
    	if (isset($forms))
    		$this->assign('forms', $forms);
    	if (isset($err_mes)) {
    		$this->assign('err_mes', $err_mes);
    	}
    
    	$this->assign('show_massg',$show_massg);
    	$this->display('user_regist.html');
    }
	
	

   
    
   
    
    
    
    
    
}